
package com.yanboo.modules.system.domain;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import com.yanboo.common.base.BaseEntity;

import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;


@Entity
@Getter
@Setter
@Table(name = "sys_menu")
public class Menu extends BaseEntity implements Serializable {


    @JSONField(serialize = false)
    @ManyToMany(mappedBy = "menus")
    @org.hibernate.annotations.ForeignKey(name = "none")
    @Schema(description = "菜单角色")
    private Set<Role> roles;

    @Schema(description = "菜单标题")
    @Column(length = 100)
    private String title;

    @Column(name = "name",length = 100)
    @Schema(description = "菜单组件名称")
    private String componentName;

    @Schema(description = "排序")
    @Column(length = 5)
    private Integer menuSort = 999;

    @Schema(description = "组件路径")
    private String component;

    @Schema(description = "路由地址")
    private String path;

    @Schema(description = "菜单类型，目录、菜单、按钮")
    @Column(length = 11)
    private Integer type;

    @Schema(description = "权限标识")
    private String permission;

    @Schema(description = "菜单图标")
    private String icon;

    //@Column(columnDefinition = "bit(1) default 0")
    @Schema(description = "缓存")
    private Boolean cache;

    //@Column(columnDefinition = "bit(1) default 0")
    @Schema(description = "是否隐藏")
    private Boolean hidden;

    @Schema(description = "上级菜单")
    @Column(length = 20)
    private Long pid;

    @Schema(description = "子节点数目", hidden = true)
    @Column(length = 5)
    private Integer subCount = 0;

    @Schema(description = "外链菜单")
    @JSONField(name = "iFrame")
    @JsonProperty("iFrame")
    private Boolean iFrame;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Menu menu = (Menu) o;
        return Objects.equals(getId(), menu.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId());
    }
}
